package com.room.search.service;

import com.room.search.domain.RoomUserBrokerChantMessage;
import com.room.search.repository.RoomUserBrokerChantMessageRepository;
import com.room.search.service.dto.RoomUserBrokerChantMessageDTO;
import com.room.search.service.mapper.RoomUserBrokerChantMessageMapper;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link RoomUserBrokerChantMessage}.
 */
@Service
@Transactional
public class RoomUserBrokerChantMessageService {

    private final Logger log = LoggerFactory.getLogger(RoomUserBrokerChantMessageService.class);

    private final RoomUserBrokerChantMessageRepository roomUserBrokerChantMessageRepository;

    private final RoomUserBrokerChantMessageMapper roomUserBrokerChantMessageMapper;

    public RoomUserBrokerChantMessageService(
        RoomUserBrokerChantMessageRepository roomUserBrokerChantMessageRepository,
        RoomUserBrokerChantMessageMapper roomUserBrokerChantMessageMapper
    ) {
        this.roomUserBrokerChantMessageRepository = roomUserBrokerChantMessageRepository;
        this.roomUserBrokerChantMessageMapper = roomUserBrokerChantMessageMapper;
    }

    /**
     * Save a roomUserBrokerChantMessage.
     *
     * @param roomUserBrokerChantMessageDTO the entity to save.
     * @return the persisted entity.
     */
    public RoomUserBrokerChantMessageDTO save(RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO) {
        log.debug("Request to save RoomUserBrokerChantMessage : {}", roomUserBrokerChantMessageDTO);
        RoomUserBrokerChantMessage roomUserBrokerChantMessage = roomUserBrokerChantMessageMapper.toEntity(roomUserBrokerChantMessageDTO);
        roomUserBrokerChantMessage = roomUserBrokerChantMessageRepository.save(roomUserBrokerChantMessage);
        return roomUserBrokerChantMessageMapper.toDto(roomUserBrokerChantMessage);
    }

    /**
     * Partially update a roomUserBrokerChantMessage.
     *
     * @param roomUserBrokerChantMessageDTO the entity to update partially.
     * @return the persisted entity.
     */
    public Optional<RoomUserBrokerChantMessageDTO> partialUpdate(RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO) {
        log.debug("Request to partially update RoomUserBrokerChantMessage : {}", roomUserBrokerChantMessageDTO);

        return roomUserBrokerChantMessageRepository
            .findById(roomUserBrokerChantMessageDTO.getId())
            .map(existingRoomUserBrokerChantMessage -> {
                roomUserBrokerChantMessageMapper.partialUpdate(existingRoomUserBrokerChantMessage, roomUserBrokerChantMessageDTO);

                return existingRoomUserBrokerChantMessage;
            })
            .map(roomUserBrokerChantMessageRepository::save)
            .map(roomUserBrokerChantMessageMapper::toDto);
    }

    /**
     * Get all the roomUserBrokerChantMessages.
     *
     * @return the list of entities.
     */
    @Transactional(readOnly = true)
    public List<RoomUserBrokerChantMessageDTO> findAll() {
        log.debug("Request to get all RoomUserBrokerChantMessages");
        return roomUserBrokerChantMessageRepository
            .findAll()
            .stream()
            .map(roomUserBrokerChantMessageMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     * Get one roomUserBrokerChantMessage by id.
     *
     * @param id the id of the entity.
     * @return the entity.
     */
    @Transactional(readOnly = true)
    public Optional<RoomUserBrokerChantMessageDTO> findOne(Long id) {
        log.debug("Request to get RoomUserBrokerChantMessage : {}", id);
        return roomUserBrokerChantMessageRepository.findById(id).map(roomUserBrokerChantMessageMapper::toDto);
    }

    /**
     * Delete the roomUserBrokerChantMessage by id.
     *
     * @param id the id of the entity.
     */
    public void delete(Long id) {
        log.debug("Request to delete RoomUserBrokerChantMessage : {}", id);
        roomUserBrokerChantMessageRepository.deleteById(id);
    }
}
